Snow Leopards - Cristal & Francesca #39
Conversation
completed wave 2
completed wave 03
There was a problem hiding this comment.
👍 Keep it up for Task List API!
Be sure to follow any final refactors shown in Learn (e.g. splitting POST and GET ALL into separate routes), and refer back to the readings for anything else that you didn't have time to finish up in activity time while working on Task List.
| migrate = Migrate() | ||
| load_dotenv() | ||
|
|
||
| def create_app(test_config=None): |
| @@ -0,0 +1,23 @@ | |||
| from app import db | |||
|
|
|||
| class Planet(db.Model): | |||
|
|
||
| planet_bp = Blueprint("planets", __name__, url_prefix="/planets") | ||
|
|
||
| def validate_planet(id): |
There was a problem hiding this comment.
👀 Consider refactoring this to receive the class type as a parameter so that our validate helper could work for more than one type. This will be helpful in Task List when adding the Goal model.
|
|
||
| return planet | ||
|
|
||
| @planet_bp.route("", methods=["GET", "POST"]) |
There was a problem hiding this comment.
Be sure to refer to the second part of creating the get all endpoint where we avoid using multiple verbs in a single endpoint.
The multiple verb approach is possible, but generally we want to avoid that (single responsibility principle).
| name_query = request.args.get("name") | ||
| flag_query = request.args.get("flag") | ||
|
|
||
| planet_query = Planet.query |
There was a problem hiding this comment.
👍 Nice job applying multiple filters.
| def get_one_planet(id): | ||
| validate_planet(id) | ||
| planet = Planet.query.get(id) | ||
| return {"id": planet.id, |
There was a problem hiding this comment.
👀 Remember to use your .to_dict() here.
| @@ -0,0 +1,28 @@ | |||
| """removed flag | |||
There was a problem hiding this comment.
Nice to see that you went through a few migrations. Keep in mind that once you've gotten your "final" table layour squared away that it can be helpful to clear out all th old migrations, recreate the empty database, and get 1 nice, clean migration. Not something we'd want to do after having real data in a production database, but it's nice to start without migration clutter.
| return app.test_client() | ||
|
|
||
| @pytest.fixture | ||
| def one_planet(app): |
There was a problem hiding this comment.
👍 Nice single-planet fixture. And great job returning the value so that it can be used in a test directly!
| flag=request_body["flag"]) | ||
| db.session.add(new_planet) | ||
| db.session.commit() | ||
| return make_response(f"planet {new_planet.name} successfully created!", 201) |
There was a problem hiding this comment.
👀 Make sure to jsonify even plain string responses, otherwise flask will return an HTML response rather than JSON.
| @@ -1,2 +1,53 @@ | |||
| from flask import Blueprint | |||
| from flask import Blueprint, jsonify, abort, make_response, request | |||
There was a problem hiding this comment.
👀 Make sure to review the readings for read, update, and delete (part 4) to make sure you have an idea for how to approach those.
There was a problem hiding this comment.
Oh no! we somehow didn't push wave 4 of solar system...looks like we picked up on an older version to complete the rest of the waves... Should we update the pull request or leave it as is?
There was a problem hiding this comment.
There are the additions in this commit - then I don't see how they disappeared: Commit: Wave 4 complete
No description provided.